import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/17 10:02
 * @description 采用递归的方式，一次性得到递增序列
 */
public class Solution {
    public static void main(String[] args) {

    }

}
class BSTIterator {
    List<Integer> list;
    int next = -1;
    public BSTIterator(TreeNode root) {
        list = new ArrayList<>();
        dfs(root, list);
    }
    public void dfs(TreeNode root, List<Integer> list) {
        if (root == null) {
            return;
        }
        dfs(root.left, list);
        list.add(root.val);
        dfs(root.right, list);
    }
    public int next() {
        next++;
        return list.get(next);
    }

    public boolean hasNext() {
        return next + 1 < list.size();
    }
}